package demo;

import javafx.animation.FillTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

// 颜色填充动画(动态,只能两种颜色)
public class FillTransitionDemo extends Application {
	private Pane root = new Pane();
	private Rectangle rectangle;
	private FillTransition fill;		// 填充动画(附带褪色效果)
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
	    rectangle = new Rectangle(200, 200, Color.YELLOW);
	    rectangle.setLayoutX(150);
	    rectangle.setLayoutY(100);
		root.getChildren().add(rectangle);
	    
		// 动画
		fill = new FillTransition(Duration.seconds(4), rectangle, Color.YELLOW, Color.DODGERBLUE);
		fill.setCycleCount(Timeline.INDEFINITE);
		fill.play();
		
	    Scene scene = new Scene(root, 500, 400);    
	    stage.setScene(scene);
		stage.show();
	}
}
